package com.hddznet.uniplatform.sm.config.mybatis;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

public class CreateEntityMapper {

	public static void main(String[] args) {
		try {
			System.out.println("--------------------start generator-------------------");
			List<String> warnings = new ArrayList<String>();
			//是否覆盖
			boolean overwrite = true;
			ClassLoader classloader = Thread.currentThread().getContextClassLoader();
			InputStream is = classloader.getResourceAsStream("com/hddznet/uniplatform/sm/config/mybatis/generatorConfig.xml");
			ConfigurationParser cp = new ConfigurationParser(warnings);
			Configuration config = cp.parseConfiguration(is);
			DefaultShellCallback callback = new DefaultShellCallback(overwrite);
			// Context context = config.getContext("context1");
			// System.out.println(context);
//            CommentGenerator commentGenerator = context.getCommentGenerator();
//            TopLevelClass topLevelClass = new TopLevelClass("");
//            topLevelClass.setVisibility(JavaVisibility.PUBLIC);
//            IntrospectedTable introspectedTable = null;
//            commentGenerator.addClassComment(topLevelClass, introspectedTable, false);

			MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
			myBatisGenerator.generate(null);
			System.out.println("--------------------end generator-------------------");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (InvalidConfigurationException e) {
			e.printStackTrace();
		} catch (XMLParserException e) {
			e.printStackTrace();
		}
	}
}
